package com.code2roc.xhood.asm;

import org.objectweb.asm.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

public class FieldEnumAnnotationVisitor extends ClassVisitor {
    private LinkedHashMap<String, String> modifyMap;

    public FieldEnumAnnotationVisitor(ClassVisitor cv, LinkedHashMap<String, String> modifyMap) {
        super(Opcodes.ASM9, cv);
        this.modifyMap = modifyMap;
    }

    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        super.visit(version, access, name, signature, superName, interfaces);
    }

    @Override
    public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
        boolean exist = false;
        for (String value:modifyMap.values()) {
            if(descriptor.contains(value)){
                exist = true;
                break;
            }
        }
        if(exist){
            AnnotationVisitor annotationVisitor = super.visitAnnotation(descriptor, visible);
            return new FiledAnnotationAdapter(annotationVisitor);
        }else{
            return super.visitAnnotation(descriptor, visible);
        }
    }
}
